# 生产者消费者模型、生产者生产数据、消费者消费数据
# 生产者将生产出的数据放在阻塞队列里、消费者再从阻塞队列里取数据


import queue,threading
import random
import time

'''生产者与消费者之间相互独立'''
# q=queue.Queue()
# def Producer(name):
#     count =0
#     while count<10:
#         print("making>>>>>>>>")
#         time.sleep(random.randrange(3))
#         q.put(count)
#         print("Producer %s has produced %s  baozi" %(name,count))
#         count +=1
#         # q.tank_done()
#         # 发送信号给队列put 数据完成
#         # q.join()
#         print("包子制作ok了")
# def Cousumer(name):
#     count = 0
#     while count < 10:
#         print("准备开始吃包子>>>>>>>>")
#         time.sleep(random.randrange(3))
#         if not q.empty():
#             data = q.get()
#             # q.task_done()
#             # q.join() # 接收队列的信息
#             print("cousumer %s has eat %s baozi" %(name,data))
#         else:
#             print("没有包子了")
#         count +=1
# p1=threading.Thread(target=Producer,args=("萌萌",))
# c1=threading.Thread(target=Cousumer,args=("蒙蒙",))
# c2=threading.Thread(target=Cousumer,args=("萌妹",))
# c3=threading.Thread(target=Cousumer,args=("梦梦",))
# p1.start()
# c1.start()
# # c2.start()
# # c3.start()
# ——————————————线程之间的通信———————————————————
'''q.tank_done() 发送信号给队列put 数据完成
   q.join() 接收来自队列的信息 成对出现在线程中'''
# q=queue.Queue()
# def Producer(name):
#     count =0
#     while count<10:
#         print("making>>>>>>>>")
#         time.sleep(random.randrange(3))
#         q.put(count)
#         print("Producer %s has produced %s  baozi" %(name,count))
#         count += 1
#         q.task_done()
#         #发送信号给队列put数据完成
#         # q.join()
#         print("包子制作ok了")
# def Cousumer(name):
#     count = 0
#     while count < 10:
#         print("准备开始吃包子>>>>>>>>")
#         time.sleep(random.randrange(3))
#         # if not q.empty():
#         data = q.get()
#         # q.task_done()
#         q.join()
#         # 接收队列的信息
#         time.sleep(4)
#         print("cousumer %s has eat %s baozi" %(name,data))
#         # else:
#         #     print("没有包子了")
#         count +=1
# p1=threading.Thread(target=Producer,args=("萌萌",))
# c1=threading.Thread(target=Cousumer,args=("蒙蒙",))
# c2=threading.Thread(target=Cousumer,args=("萌妹",))
# c3=threading.Thread(target=Cousumer,args=("梦梦",))
# p1.start()
# c1.start()
# c2.start()
# c3.start()
# print("end")
# ------------------------------------------------------
q=queue.Queue()
def Producer(name):
    count =0
    while count<10:
        print("making>>>>>>>>")
        time.sleep(random.randrange(3))
        q.put(count)
        print("Producer %s has produced %s  baozi" %(name,count))
        q.join()
        count += 1
        print("包子制作ok了")
def Cousumer(name):
    count = 0
    while count < 10:
        print("准备开始吃包子>>>>>>>>")
        time.sleep(random.randrange(3))
        data = q.get()
        q.task_done()
        time.sleep(4)
        print("cousumer %s has eat %s baozi" %(name,data))
        count +=1
p1=threading.Thread(target=Producer,args=("萌萌",))
c1=threading.Thread(target=Cousumer,args=("蒙蒙",))
c2=threading.Thread(target=Cousumer,args=("萌妹",))
c3=threading.Thread(target=Cousumer,args=("梦梦",))
p1.start()
c1.start()
c2.start()
c3.start()
print("end all ")